#include "TcpServer.hpp"
#include "Protocol.hpp"
#include "NetCol.hpp"
#include "Daemon.hpp"

void USERAGE(char* s)
{
    std::cerr << s << " port" << std::endl;
}
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        USERAGE(argv[0]);
        exit(USERAGE_ERR);
    }
    std::cout << "守护进程..." << std::endl;
    Daemon(0, 0);
    //Enable_Console_Log_Strategy();
    Enable_File_Log_Strategy();


    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<NetCol> nc = std::make_unique<NetCol>();
    std::unique_ptr<Protocol> pro = std::make_unique<Protocol>(
        [&nc](Request& req)->Response{
            return nc->Excute(req);
        }
    );

    std::unique_ptr<TcpServer> t = std::make_unique<TcpServer>(port,
        [&pro](std::shared_ptr<Socket>& sock, Inet_Addr addr)
        {
            pro->GetRequest(sock, addr);
        });
        t->Start();
    return 0;
}